﻿using MslDiary.Model;
using System;
using System.Collections.Generic;

// 版权所有：2014  All Rights Reserved.
// 文 件 名：A_Note.cs
// 功能描述：
// 创建标识：m.sh.lin0328@163.com 2014/12/13 19:03:30
// 修改描述：
//----------------------------------------------------------------*/
namespace MslDiary.BLL
{
    public class A_NoteBLL : MSL.Tool.Data.DBAccessBase<Model.A_Note>
    {
        public A_NoteBLL()
            : base("A_Note", "Id", true)
        {

        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="type">查询类别</param>
        /// <param name="whereSql">条件</param>
        /// <param name="pageSize"></param>
        /// <param name="pageIndex"></param>
        /// <param name="sortBy"></param>
        /// <param name="recordCount"></param>
        /// <returns></returns>
        public List<A_Note> GetPageList(Model.SearchType type, string whereSql, int pageSize, int pageIndex, string sortBy, out int recordCount)
        {
            List<A_Note> list = new List<A_Note>();
            string table = @"(
                                SELECT A.Id,A.Title,A.IsDelete,B.Name AS TypeName,A.TypeId,A.CreateDate,A.ModifyDate,A.Summary 
                                FROM A_Note A LEFT JOIN A_Item B ON A.TypeId=B.Id 
                                WHERE B.FatherId=1 
                            ) AS A
                            ";
            #region 条件

            string where = " 1=1 AND IsDelete='0' ";
            if (!String.IsNullOrEmpty(whereSql))
                where += " AND " + whereSql;
            switch (type)
            {
                case Model.SearchType.All:
                    break;
                case Model.SearchType.Year://今年
                    where += " AND CreateDate>=datetime('" + DateTime.Now.Year + "-01-01')";
                    break;
                case Model.SearchType.Month://当月
                    where += " AND CreateDate>=datetime('" + DateTime.Now.ToString("yyyy-MM-01") + "')";
                    break;
                case Model.SearchType.Day://当天
                    where += " AND date(CreateDate)=datetime('" + DateTime.Now.ToString("yyyy-MM-dd") + "')";
                    break;
                case Model.SearchType.Lately7Days://最近7天
                    where += " AND CreateDate>=datetime('" + DateTime.Now.AddDays(-7).ToString("yyyy-MM-dd") + "')";
                    break;
                case Model.SearchType.Lately30Days://最近30天
                    where += " AND CreateDate>=datetime('" + DateTime.Now.AddDays(-30).ToString("yyyy-MM-dd") + "')";
                    break;
                default:
                    break;
            }
            #endregion
            list = base.GetList(null, table, pageSize, pageIndex, "*", where, sortBy, out recordCount);
            return list;
        }
    }
}
